package pers.course.week9;

import java.util.*;

public class Winner {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        HashMap<String, Integer> map = new HashMap<>();
        String[] a = new String[1001];
        int[] b = new int[1001];
        int n = in.nextInt();
        // 第一轮模拟计算各玩家分数
        for (int i = 0; i < n; i++) {
            a[i] = in.next();
            b[i] = in.nextInt();
            int x = b[i];
            if (map.containsKey(a[i]))
                x += map.get(a[i]);
            map.put(a[i], x);
        }
        // 找出最高分并清空模拟结果
        int max = 0;
        for (Object obj : map.keySet())
            max = Math.max(max, map.get(obj));
        for (Object obj : map.keySet()) {
            map.put(obj.toString(), 0);
        }
        // 第二轮模拟找到最先达到最高分的玩家
        for (int i = 0; i < n; i++) {
            int x = b[i];
            if (map.containsKey(a[i]))
                x += map.get(a[i]);
            map.put(a[i], x);
            if (x >= max) {
                System.out.println(a[i]);
                break;
            }
        }
    }
}
